﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using NServiceBus.Host.Internal;

#endregion

namespace EsbMonitorExtension.Infrastructure
{
    public class TypesFinder : ITypesFinder
    {
        public IEnumerable<Type> ScanAssembliesFor<T>()
        {
            foreach (Assembly assembly in AssemblyScanner.GetScannableAssemblies())
            {
                foreach (Type type in assembly.GetTypes().
                    Where(t => typeof (T).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract))
                {
                    yield return type;
                }
            }
        }
    }

    public interface ITypesFinder
    {
        IEnumerable<Type> ScanAssembliesFor<T>();
    }
}